﻿#pragma once

#include <QObject>
#include "BaseShader.h"

class PixelInversionShader : public BaseShader
{
	Q_OBJECT

public:
	/*static BaseShader* Get()
	{
		static PixelInversionShader pis;
		return &pis;
	}*/
	PixelInversionShader(QObject* parent = nullptr);
	~PixelInversionShader();
private:
	//顶点着色器代码
	QString vertexSource = R"(
	attribute vec4 vertexIn;
	attribute vec2 textureIn;
	varying vec2 textureOut;
	void main(void)
	{
		gl_Position = vertexIn;
		textureOut = textureIn;
	}
	)";

	//片元着色器代码
	QString fragmentSource = R"(
	varying vec2 textureOut;
	uniform sampler2D tex_y;
	uniform sampler2D tex_u;
	uniform sampler2D tex_v;
	void main(void)
	{
		vec3 yuv;
		vec3 rgb;
		yuv.x = texture2D(tex_y, textureOut).r;
		yuv.y = texture2D(tex_u, textureOut).r - 0.5;
		yuv.z = texture2D(tex_v, textureOut).r - 0.5;
		rgb = mat3(1.0, 1.0, 1.0,
			0.0, -0.39465, 2.03211,
			1.13983, -0.58060, 0.0) * yuv;
		// 像素取反：1.0 - 原始颜色值
		rgb = 1.0 - rgb;
		 // 使用灰度值作为RGB输出
		gl_FragColor = vec4(rgb, 1.0);
	}
	)";
};
